<?php
$Items = $this->Items;
?>
<script type="text/javascript">
    function loadPage(x,url){
        var div_name = 'div#status' + x;
        //$(div_name).html('');
        $(div_name).load(url);
    }
</script>
<div class="content-box bt-space20">
    <div class="box-body">
        <div class="box-wrap clear">

            <!-- BASIC STYLE TABLE -->
            <h2>Category Manager</h2>

            <table class="style1" cellspacing="0">
                <caption valign="middle">List of Category
                    <span style="float: right;">
                        <?php $lnkAdd = $this->url(array('module' => 'admin', 'controller' => 'category', 'action' => 'add')); ?>
                        <button class="button red small" type="button" onclick="toSite('<?php echo $lnkAdd; ?>')">Add</button>
                    </span>
                </caption>
                <thead>
                    <tr>
                        <th>Name</th>
                        <th align="center">Status</th>
                        <th align="center">&nbsp;&nbsp;&nbsp;Order</th>
                        <th align="center">Action</th>
                        <th align="center">Id</th>
                    </tr>
                </thead>
                <tbody>
                    <?php
                    if (count($this->Items) > 0) {
                        foreach ($this->Items as $key => $val) {
                            $id = $val['id'];
                            $name = $val['name'];
                            $urlProduct = $this->url(array('module' => 'admin', 'controller' => 'product',
                                'action' => 'index', 'cat_id' => $val['id']));
                            $lnkProduct = ' - <a href="' . $urlProduct . '" />Manager</a>';

                            $status = '<div id="status' . $id . '">';

                            $lnkStatus = $this->url(array('module' => 'admin', 'controller' => 'category',
                                'action' => 'status', 'id' => $val['id'], 'status' => $val['status']));
                            if ($val['status'] == 1) {
                                $status .= '<span class="pointer" onclick=loadPage("' . $val['id'] . '","' . $lnkStatus . '") ><img src="images/active.png"></span>';
                            } else {
                                $status .= '<span class="pointer" onclick=loadPage("' . $val['id'] . '","' . $lnkStatus . '") ><img src="images/inactive.png"></span>';
                            }
                            $status .= '</div>';

                            $order = $val['order'];

                            if ($val['level'] == 1) {
                                $name = '<div><img src="images/ball_green_13.png"> ' . $val['name'] . '</div>';
                            } else {
                                $x = ($val['level'] - 1) * 50;
                                $css = 'padding-left:' . $x . 'px';
                                $name = '<div style="' . $css . '"><img src="images/ball_grey_13.png"> ' . $val['name'] . $lnkProduct . '</div>';
                            }
                            $lnkEdit = $this->url(array('module' => 'admin', 'controller' => 'category', 'action' => 'edit', 'id' => $val['id']))
                            ?>
                            <tr>
                                <td valign="bottom"><?php echo $name; ?></td>
                                <td><?php echo $status; ?></td>
                                <td
                                <?php
                                if ($val['parent'] == 0)
                                    echo 'align="left"';
                                else
                                    echo 'align="center"';
                                ?>
                                    ><?php echo $order; ?></td>
                                <td>
                                    <a href="<?php echo $lnkEdit; ?>"><img src="images/ico_settings_16.png" class="fl-space" alt=""></a>
                                    <a href="#delete<?php echo $id; ?>" class="modal-link"><img src="images/ico_delete_16.png" class="fl" alt=""></a>
                                </td>
                                <td><?php echo $id; ?></td>
                            </tr>
                        <div id="delete<?php echo $id; ?>" class="modal-window modal-400">
                            <p></p>
        <?php $url = $this->url(array('module' => 'admin', 'controller' => 'category', 'action' => 'delete', 'id' => $id)); ?>
                            <h2>Warning...!!!!!!!</h2>
                            <p>Bạn có chắc chắc muốn <b>xóa</b> category này không ???</p>
                            <p>Lưu ý : Khi bạn xóa 1 category thì tất cả category con của nó và các sản phẩm thuộc các category đó đều bị xóa.Cẩn thận !!!</p>
                            <p>Lời khuyên : Bạn không nên xóa mà chỉ cần làm ẩn Category mình muốn xóa thôi !!!</p>
                            <button class="green small" type="button" onclick="toSite('<?php echo $url; ?>')">Đồng ý xóa</button>
                        </div>
                        <?php
                    }
                }
                ?>
                </tbody>
            </table>

        </div> <!-- end of box-wrap -->
    </div> <!-- end of box-body -->
</div> <!-- end of content-box -->